<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redis;
use App\Model\Address;

class CartController extends Controller
{
  // 购物车
	public function index()
	{
		$datas = [
      [
        'shop_id' => '1',
        'shop_name'=> '商品名1',
        'shop_pic' => '图片',
        'shop_money'=> '1000',
        'shop_mun' => '2'
      ],
      [
        'shop_id' => '2',
        'shop_name'=> '商品名2',
        'shop_pic' => '图片2',
        'shop_money'=> '2000',
        'shop_mun' => '3'
      ]
    ];
		$redisSet = Redis::set(session()->getId(), serialize($datas));

		// $values = Redis::lrange('names', 5, 10);
		$getId = Redis::get(session()->getId());
    $data = unserialize($getId);
		$money = 0;
		foreach ($data as $v) {
			$money += $v['shop_money']*$v['shop_mun'];
		}
		return view('Home/Cart',['data' => $data,'money' =>$money]);
	}
	// 购买页
	public function Pay()
	{
		$id=1;
		$address = Address::where('id',$id)->get();
		$getId = Redis::get(session()->getId());
    $data = unserialize($getId);
		$money = 0;
		foreach ($data as $v) {
			$money += $v['shop_money']*$v['shop_mun'];
		}
		return view('Home/Pay',['money' =>$money, 'data' => $data, 'address' => $address]);
	}
}
